package com.xd.service.admin.XTGLY.impl;
import com.xd.Dto.ProductPageQueryDTO;
import com.xd.Entity.ProductEntity;
import com.xd.Mapper.ProductMapper;
import com.xd.Result.CommonResult;
import com.xd.Result.PageResult;
import com.xd.erroCode.Errcode;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xd.service.admin.XTGLY.BrandProductService;
import com.xd.vo.productVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BrandProductServiceImpl implements BrandProductService {
    @Autowired
    ProductMapper productMapper;

    @Override
    public PageResult getBrand(ProductPageQueryDTO productPageQueryDTO) {
        PageHelper.startPage(productPageQueryDTO.getPage(), productPageQueryDTO.getPageSize());
        Page page = productMapper.getBrand(productPageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public CommonResult getBrandToADDProduct(productVo productVo) {
//        根据商品品牌校验
        System.out.println(productVo.getBrandId());
        ProductEntity productEntityByBrand = productMapper.selectBrandById(productVo.getBrandId());

//     根据商品分类校验
        ProductEntity productEntityByCatergory = productMapper.selectCatergoryById(productVo.getCategoryId());

//        根据，商品单位校验

        ProductEntity productEntityByUnit = productMapper.selectUnitById(productVo.getTonId());

        if (productEntityByBrand == null) {
            return CommonResult.error(Errcode.NOT_BRAND, productEntityByBrand);
        }
        if (productEntityByCatergory == null) {
            return CommonResult.error(Errcode.NOT_CATEGORY, productEntityByCatergory);
        }

        if (productEntityByUnit == null) {
            return CommonResult.error(Errcode.NOT_UNIT, productEntityByUnit);
        }
        return  CommonResult.Success();
    }
}
